<script setup lang="ts">
	import {ref,reactive,getCurrentInstance} from 'vue'
	import { onLoad ,onShow} from '@dcloudio/uni-app';
	const {proxy} = getCurrentInstance()
	let obj = ref({})
	let cancelOrderReason = ref([])
	const copy = () => {
		uni.setClipboardData({
			data: obj.value.orderno,
			success: () => {
				uni.showToast({
					icon: 'none',
					title: '复制成功'
				});
			}
		});
	}
	onLoad((option) => {
		getInfo(option.id)
		getCancelOrderReason()
	})
	const getInfo = (id)=>{
		proxy.$req('GET', proxy.$api.meiyeShortWordersOrderGetOrderDetail,{
			orderId:id,
		}).then((res) => {
			if(res.code === 200){
				obj.value = res.result
			}
		})
	}
	
	const showPopup = ref(false)
	const close = ()=>{
		showPopup.value = false
	}
	const open = ()=>{
		
	}
	const cancelSubmit = ()=>{
		if(obj.value.reasonId == '' || obj.value.reasonId == undefined){
			uni.showToast({
				icon: 'none',
				title: '请选择取消原因'
			});
			return
		}
		cancelOrder()
	}
	const radioChange = (n) => {
		obj.value.reasonId = n
		console.log('radioChange', n);
	};
	//取消订单原因
	const getCancelOrderReason = ()=>{
		const par  ={
			pageNo:1,
			pageSize:10
		}
		proxy.$req('GET', proxy.$api.meiyeShortWorkerCancelList,par).then((res) => {
			if(res.code === 200){
				cancelOrderReason.value  = res.result.records
			}
		})
	}
	//取消订单
	const cancelOrder = () => {
		const par={
		  "operationType": 4,
		  "orderId": obj.value.id,
		  "reasonId":cancelOrderReason.value[0].id,//后面这里芳选择的取消原因的id
		  "userTimePeriodId":obj.value.period,
		  
		}
		proxy.$req('PUT', proxy.$api.meiyeShortWordersOrderCancelOrder,par).then((res) => {
			if(res.code !== 200){
				uni.$u.toast(res.message)
			}else{
				getInfo()
			}
		})
	}
	//删除订单
	const delOrder = ()=>{
		proxy.$req('DELETE', proxy.$api.deleteEmployerOrderByEmp+'/'+obj.value.id).then((res) => {
			if(res.code !== 200){
				uni.$u.toast(res.message)
			}else{
				//  返回上一页
			}
		})
	}
	//完成验收
	const acceptanceOrder = (e) => {
		const par={
		  "operationType": 3,
		  "orderId": obj.value.id,
		  "userTimePeriodId":obj.value.period
		}
		proxy.$req('PUT', proxy.$api.completeAcceptanceOrder,par).then((res) => {
			if(res.code !== 200){
				uni.$u.toast(res.message)
			}else{
				getInfo()
			}
		})
	}
	//支付钱钱
	const paymoney = (e)=>{
		proxy.$req('POST', proxy.$api.shortWorkerPay,{
			"orderId": obj.value.id,
			"orderNo": obj.value.orderno
		}).then((res) => {
			uni.$u.toast(res.message)
			if (res.success) {
				let url = JSON.parse(res.result.result).resp_data.counter_url
				// #ifdef APP-PLUS
				plus.runtime.openURL(url)
				console.log('app');
				// #endif
				// #ifdef H5
				window.open(url)
				console.log('h5');
				// #endif
				//支付成功或者失败的回调缺少
			}
		})
	}
</script>

<template>
	<u-navbar class="navbar"  bgColor="rgba(255, 255, 255, 0)" :placeholder="true" title="" :autoBack="true">
		<template #center>
			<view style="font-weight: 600;">订单详情</view>
		</template>
	</u-navbar>
	<view class="mainBox">
		<view class="mianBoxH">
			<view class="headL">
				{{obj.employmentType==0?`日雇佣·${obj.num}日`:`小时雇佣·${obj.num}小时`}}
			</view>
			<view class="headR">
				{{['未支付','已支付','待接单','待服务','待验收','已完成','已取消'][obj.status+2]}}
			</view>
		</view>
		<view class="mainC">
			<view class="line">
				<view class="lineL">
					雇佣类型
				</view>
				<text class="lineR">{{obj.employmentType==0?"按日":'按小时'}}</text>
			</view>
			<view class="line">
				<view class="lineL">
					雇佣时间
				</view>
				<text class="lineR">{{obj.employeeDateTime?obj.employeeDateTime.workDate:''}}</text>
			</view>
			<view class="line">
				<view class="lineL">
					短时工
				</view>
				<text class="lineR" v-if="obj.shortWorkInfo">{{obj.shortWorkInfo.shortWorkerName}}|{{obj.shortWorkInfo.shortWorkerPhone}}</text>
			</view>
			<view class="line">
				<view class="lineL">
					工作地点
				</view>
				<text class="lineR">{{obj.address}}</text>
			</view>
			<view class="lineEnd">
				<view class="endR">
					<text class="xinzi">薪资</text><text class="yuan">￥</text><text class="num intFont">{{obj.salary}}</text>
				</view>
			</view>
		</view>
		<view class="afterSales">
			<view class="line">
				<view class="lineL">
					退款原因
				</view>
				<view class="lineR">
					{{obj.reasonRefund}}
				</view>
			</view>
			<view class="line">
				<view class="lineL">
					退还金额
				</view>
				<view class="lineR intFont">
					{{obj.refundAmount?`￥${obj.refundAmount}`:``}}
				</view>
			</view>
			<view class="line">
				<view class="lineL">
					申请时间
				</view>
				<view class="lineR">
					{{obj.refundApplyTime}}
				</view>
			</view>
			<view class="line">
				<view class="lineL">
					退款时间
				</view>
				<view class="lineR">
					{{obj.refundTime}}
				</view>
			</view>
		</view>
		<view class="mainFoot">
			<view class="line">
				<view class="lineL">
					订单编号
				</view>
				<view class="">
					<text class="lineR">{{obj.orderno}}</text>
					<text class="copy" @click="copy">复制</text>
				</view>
			</view>
			<view class="line">
				<view class="lineL">
					下单时间
				</view>
				<view class="lineR intFont">
					{{obj.orderTime}}
				</view>
			</view>
			<view class="line">
				<view class="lineL">
					支付时间
				</view>
				<view class="lineR">
					{{obj.payTime}}
				</view>
			</view>
			<view class="line">
				<view class="lineL">
					完成时间
				</view>
				<view class="lineR">
					{{obj.finishTime}}
				</view>
			</view>
		</view>
	</view>
	
	<u-popup :show="showPopup" :round="10" @close="close" @open="open">
		<view class="popupMain">
			<view class="title">选择取消原因</view>
			<u-radio-group placement="column">
			    <u-radio
					:customStyle="{marginBottom: '18px'}"
					v-for="item in cancelOrderReason"
					:key="item.id"
					:label="item.cancelContent"
					:name="item.id"
					@change="radioChange"
			    >
			    </u-radio>
			</u-radio-group>
			<view class="popupBtn" @click="cancelSubmit">
				<text>确认取消</text>
				<text>服务开始24小时内不可取消</text>
			</view>
		</view>
		
	</u-popup>
</template>

<style lang="scss">
	page{
		background: #FAFAFA;
	}
	.popupMain{
		padding:20rpx;
		.title{
			padding:40rpx 18rpx;
		}
		.popupBtn{
			display:flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			background:#CB645E;
			width:80%;
			padding:8rpx 0;
			margin:20rpx auto;
			color:#fff;
			border-radius: 16rpx;
			text:nth-child(1){
				font-size:28rpx;
				
			}
			text:nth-child(2){
				font-size:24rpx;
				
			}
			
		}
	}
	.mainBox{
		width: 686rpx;
		height: 990rpx;
		background: #FFFFFF;
		box-shadow: 8rpx 8rpx 32rpx 0rpx rgba(0,0,0,0.04);
		border: 2rpx solid #FFFFFF;
		margin:20rpx auto;
		border-radius: 20rpx;
		padding: 20rpx 10rpx;
		box-sizing: border-box;
		.afterSales{
			border-bottom:1rpx solid rgba(0,0,0,0.05);
			padding: 20rpx 20rpx;
			box-sizing: border-box;
			.line{
				display: flex;
				justify-content: space-between;
				margin: 15rpx 0;
				.lineL{
					font-size: 28rpx;
					font-weight: 600;
				}
				.lineR{
					font-size: 24rpx;
					font-weight: 400;
					color: rgba(0,0,0,0.65);
					line-height: 34rpx;
				}
			}
		}
		.mainFoot{
			margin-top: 20rpx;
			padding: 20rpx 20rpx 0 20rpx;
			box-sizing: border-box;
			.line{
				display: flex;
				justify-content: space-between;
				margin: 15rpx 0;
				.copy{
					width: 48rpx;
					height: 34rpx;
					font-size: 24rpx;
					font-weight: 400;
					color: black;
					border-left: 1rpx solid #ccc;
					margin-left: 5rpx;
					padding-left: 5rpx;
				}
				.lineL{
					font-size: 28rpx;
					font-weight: 600;
				}
				.lineR{
					font-size: 24rpx;
					font-weight: 400;
					color: rgba(0,0,0,0.65);
					line-height: 34rpx;
				}
			}
		}
		.mainC{
			margin-top: 20rpx;
			border-bottom: 1rpx solid rgba(0,0,0,0.05);
			padding-bottom: 70rpx;
			.lineEnd{
				width: 650rpx;
				margin: 0 auto;
				padding: 10rpx 20rpx;
				box-sizing: border-box;
				.endR{
					float: right;
					.xinzi{
						display: inline-block;
						font-size: 32rpx;
						font-weight: 600;
						margin-right: 10rpx;
					}
					.yuan{
						font-size: 28rpx;
						font-weight: bold;
						color: #F22F19;
					}
					.num{
						font-size: 44rpx;
						font-weight: bold;
						color: #F22F19;
						line-height: 52rpx;
					}
				}
			}
			.line{
				width: 650rpx;
				height: 64rpx;
				padding: 0 20rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;
				.lineL{
					font-size: 28rpx;
					font-weight: 600;
					
				}
				.lineR{
					width: 460rpx;
					color: #3b3b3b;
					font-size: 28rpx;
					font-weight: 400;
					
				}
			}
		}
		.mianBoxH{
			height: 80rpx;
			padding: 10rpx 10rpx;
			box-sizing: border-box;
			display: flex;
			margin: 0 auto;
			justify-content: space-between;
			width: 654rpx;
			border-bottom: 1rpx solid rgba(0,0,0,0.05);
			.headL{
				font-size: 32rpx;
				font-weight: 600;
				color: #000000;
			}
			.headR{
				font-size: 28rpx;
				font-weight: 400;
				color: #F22F19;
			}
		}
	}
</style>
